<template>
  <el-container class="layout-container">
    <el-aside width="200px">
      <el-menu
          :default-active="$route.path"
          router
          class="sidebar-menu"
      >
        <el-menu-item index="/admin/dashboard">
          <el-icon><House /></el-icon>
          <span>仪表盘</span>
        </el-menu-item>

        <el-sub-menu index="1">
          <template #title>
            <el-icon><User /></el-icon>
            <span>员工管理</span>
          </template>
          <el-menu-item index="/admin/employee">员工列表</el-menu-item>
        </el-sub-menu>

        <el-sub-menu index="2">
          <template #title>
            <el-icon><FolderOpened /></el-icon>
            <span>药材分类</span>
          </template>
          <el-menu-item index="/admin/herb-category">分类管理</el-menu-item>
        </el-sub-menu>

        <el-sub-menu index="3">
          <template #title>
            <el-icon><Collection /></el-icon>
            <span>中药材</span>
          </template>
          <el-menu-item index="/admin/chinese-herb">药材管理</el-menu-item>
        </el-sub-menu>

        <el-sub-menu index="4">
          <template #title>
            <el-icon><Box /></el-icon>
            <span>库存管理</span>
          </template>
          <el-menu-item index="/admin/herb-inventory">库存管理</el-menu-item>
          <el-menu-item index="/admin/herb-inventory/warning">库存预警</el-menu-item>
          <el-menu-item index="/admin/herb-inventory/expiring">即将过期</el-menu-item>
        </el-sub-menu>

        <el-menu-item index="/admin/chat-assistant">
          <el-icon><ChatDotRound /></el-icon>
          <span>中医药问答小助手</span>
        </el-menu-item>
      </el-menu>

    </el-aside>

    <el-container>
      <el-header>
        <div class="header-content">
          <div class="header-left">
            <h3>中药材管理系统</h3>
          </div>
          <div class="header-right">
            <el-dropdown @command="handleCommand">
              <span class="user-info">
                <el-icon><User /></el-icon>
                {{ authStore.userInfo.name }}
              </span>
              <template #dropdown>
                <el-dropdown-menu>
                  <el-dropdown-item command="logout">退出登录</el-dropdown-item>
                </el-dropdown-menu>
              </template>
            </el-dropdown>
          </div>
        </div>
      </el-header>

      <el-main>
        <router-view />
      </el-main>
    </el-container>
  </el-container>
</template>

<script setup>
import { useRouter } from 'vue-router'
import { useAuthStore } from '@/stores/auth'

const router = useRouter()
const authStore = useAuthStore()

const handleCommand = (command) => {
  if (command === 'logout') {
    // 使用新的store方法清除登录信息
    authStore.removeLoginEmp()
    router.push('/admin/login')
  }
}
</script>

<style scoped>
.layout-container {
  height: 100vh;
}

.sidebar-menu {
  height: 100%;
}

.el-header {
  background-color: #fff;
  border-bottom: 1px solid #e6e6e6;
  display: flex;
  align-items: center;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}

.user-info {
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
}

.el-main {
  background-color: #f5f5f5;
  padding: 20px;
}
</style>
